#include "workspacefactory.h"


void WorkspaceFactory::addCell(int x, int y){
    (robots.back())->addCellToPath(cellMatrix[x][y]);
}
void WorkspaceFactory::addRobot(int id){
    Robot* r = new Robot(id);
    robots.push_back(r);
}

void WorkspaceFactory::print(){
    std::list<Robot*>::iterator it;
    for(it=this->robots.begin();it!=this->robots.end();++it){
        (*it)->printPath();
    }
}

void WorkspaceFactory::createMatrix(int size){

    this->size=size;
    this->cellMatrix = new Cell**[size];

    for (int i =0; i<size;i++){
        cellMatrix[i]=new Cell*[size];
        for (int j=0; j<size;j++){
            cellMatrix[i][j] = new Cell(i,j);
        }
    }
    std::cout<<"after creation"<<std::endl;
//    for (int i =0; i<size;i++){
//        for (int j =0; j<size;j++){
//            cellMatrix[i][j]->printCell();std::cout<<" ";
//        }
//        std::cout<<std::endl;
//    }


    //pCellMatix=cellMatrix;
}

Workspace* WorkspaceFactory::createWorkspace(){
    Workspace *ws = new Workspace();
    std::list<Robot*>::iterator it;
    ws->setSize(this->size,this->size);
    ws->cellMatrix = this->cellMatrix;
    std::cout<<"in createWorkspace"<<std::endl;
    for (int i =0; i<size;i++){
        for(int j=0; j<size;j++){
            cellMatrix[i][j]->printCell();
            std::cout<<"\t";
        }
        std::cout<<std::endl;
    }
    ws->setRobots(this->robots);
    //this->print();
    return ws;
}
